{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "t:  (2,) <class 'tuple'>\n",
      "a:  (1, 2, 3)\n",
      "b:  (1, 2, 3)\n"
     ]
    }
   ],
   "source": [
    "# 初始化\n",
    "t = (2,)\n",
    "a = tuple([1,2,3])\n",
    "b = tuple({1,2,3})\n",
    "\n",
    "\n",
    "print('t: ', t, type(t))\n",
    "print('a: ', a)\n",
    "print('b: ', b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "1\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "tuple.index(x): x not in tuple",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m/Users/apple/dsc/dsc/26.dict_list_set_tuple_常用方法/tuple.ipynb Cell 2\u001b[0m in \u001b[0;36m<cell line: 6>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      <a href='vscode-notebook-cell:/Users/apple/dsc/dsc/26.dict_list_set_tuple_%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/tuple.ipynb#W1sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m \u001b[39mprint\u001b[39m(a[\u001b[39m0\u001b[39m])\n\u001b[1;32m      <a href='vscode-notebook-cell:/Users/apple/dsc/dsc/26.dict_list_set_tuple_%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/tuple.ipynb#W1sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m \u001b[39mprint\u001b[39m(a\u001b[39m.\u001b[39mcount(\u001b[39m1\u001b[39m))\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/apple/dsc/dsc/26.dict_list_set_tuple_%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/tuple.ipynb#W1sZmlsZQ%3D%3D?line=5'>6</a>\u001b[0m a\u001b[39m.\u001b[39;49mindex(\u001b[39m-\u001b[39;49m\u001b[39m2\u001b[39;49m)\n",
      "\u001b[0;31mValueError\u001b[0m: tuple.index(x): x not in tuple"
     ]
    }
   ],
   "source": [
    "# 计数， 查找， \n",
    "a = (1,2,3,4)\n",
    "\n",
    "print(a[0])          # 查找 索引\n",
    "print(a.count(1))    # 计数\n",
    "\n",
    "a.index(-2)          # 查找 index， 没有元素，会报错"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.12 ('opencv')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "b04e532e6ce11d72ca7f2113c964d7a5531c18c5e6d3e97b1c42c6f9a3724305"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
